package api

import (
	"github.com/gin-gonic/gin"
	"github.com/share309/gojwt"
	"house/api/handler"
	"house/api/middleware"
	"house/consts"
)

func LoadRouters(r *gin.Engine) {
	r.Use(middleware.Cors()) //跨域

	api := r.Group("/api")
	{
		index := api.Group("/index") //默认
		{
			index.POST("/register", handler.Register)            //注册
			index.POST("/login", handler.Login)                  //登录
			index.GET("/getHouseList", handler.GetHouseList)     //房源列表
			index.GET("/getHouseDetail", handler.GetHouseDetail) //房源详情
		}

		api.Use(gojwt.JWTAuth(consts.JWT_KEY)) //token认证

		user := api.Group("/user") //用户
		{
			user.POST("/refreshToken", handler.RefreshToken) //刷新token
		}

		house := api.Group("/house") //房源
		{
			house.POST("/add", handler.AddHouse)                 //发布房源
			house.POST("/updatePrice", handler.UpdateHousePrice) //房价调整
		}

		reservation := api.Group("/reservation") //预约
		{
			reservation.POST("/add", handler.AddReservation) //添加预约
			reservation.POST("/del", handler.DelReservation) //取消预约
		}

		order := api.Group("/order") //订单
		{
			order.POST("/add", handler.AddOrder)              //添加订单
			order.POST("/uploadPayUrl", handler.UploadPayUrl) //上传首付凭证
		}

		admin := api.Group("/admin") //管理员
		{
			admin.GET("/getOrderList", handler.GetOrderList)            //查看订单列表
			admin.POST("/updateOrderStatus", handler.UpdateOrderStatus) //更新订单状态
		}

		upload := api.Group("/upload") //上传
		{
			upload.POST("/houseImage", handler.UploadHouseImage) //上传房源图片
			upload.POST("/houseVideo", handler.UploadHouseVideo) //上传房源视频
		}

		chat := api.Group("/chat") //聊天
		{
			chat.GET("/ws", handler.Chat)
		}
	}
}
